package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.smedi.ismedi.inmail.api.dto.request.appPush.NotificationMessageRequest;
import com.smedi.ismedi.inmail.api.dto.request.appPush.TransmissionMessageRequest;
import com.smedi.ismedi.inmail.api.feign.RemoteDataMiddlePlatformFeignApi;
import com.smedi.ismedi.inmail.core.application.command.NotificationMessageCommand;
import com.smedi.ismedi.inmail.core.application.command.TransmissionMessageCommand;
import com.smedi.ismedi.inmail.core.application.service.AppPushApplicationService;
import com.smedi.ismedi.inmail.core.application.service.WeatherApplicationService;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * 通知公告Controller
 *
 * @author jiangqinxuan
 * @date 2021/07/26
 */
@AllArgsConstructor
@RestController
public class DataMiddlePlatformController implements RemoteDataMiddlePlatformFeignApi {
    private final WeatherApplicationService weatherApplicationService;
    private final AppPushApplicationService appPushApplicationService;
    private final DozerUtil dozerUtil;

    @Override
    public ResponseData<String> getWeather(String cityName, LocalDate date) {
        String weather = weatherApplicationService.getWeather(cityName, date);
        return new ResponseData<>().success(weather);
    }

    @Override
    public ResponseData<String> pushPassThroughMessageSingle(TransmissionMessageRequest passThroughMessage) {
        TransmissionMessageCommand passThroughMessageCommand = dozerUtil.convertor(passThroughMessage, TransmissionMessageCommand.class);
        String result = appPushApplicationService.pushPassThroughMessageSingle(passThroughMessageCommand);
        return new ResponseData<>().success(result);
    }
    @Override
    public ResponseData<String> pushPassThroughMessageBatch(TransmissionMessageRequest passThroughMessage) {
        TransmissionMessageCommand passThroughMessageCommand = dozerUtil.convertor(passThroughMessage, TransmissionMessageCommand.class);
        String result = appPushApplicationService.pushPassThroughMessageBatch(passThroughMessageCommand);
        return new ResponseData<>().success(result);
    }

    @Override
    public ResponseData<String> pushNotificationMessage(NotificationMessageRequest notificationMessage) {
        NotificationMessageCommand notificationMessageCommand = dozerUtil.convertor(notificationMessage, NotificationMessageCommand.class);
        String result = appPushApplicationService.pushNotificationMessage(notificationMessageCommand);
        return new ResponseData<>().success(result);
    }
}
